package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemRequestRemote;
import com.cskaoyan.shopping.converter.CartItemConverter;
import com.cskaoyan.shopping.dal.entitys.Item;
import com.cskaoyan.shopping.dal.persistence.ItemMapper;
import com.cskaoyan.shopping.dto.CartProductDto;
import com.cskaoyan.shopping.service.ICartOrderService;
import com.cskaoyan.user.dal.entitys.UserVerify;
import com.cskaoyan.user.dal.persistence.UserVerifyMapper;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * Created with IntelliJ IDEA.
 *
 * @Author:ZhangShuPeng
 * @Date:2023/01/10/20:57
 * @Description:
 */

@Service
public class ICartOrderServiceImpl implements ICartOrderService {

    //@Autowired
    //UserVerifyMapper userVerifyMapper;

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    CartItemConverter cartItemConverter;

    @Autowired
    RedissonClient redissonClient;

    @Override
    public void clearCartItemByUserID(ClearCartItemRequestRemote request) {
        Long userId = request.getUserId();
        //UserVerify userVerify = userVerifyMapper.selectByPrimary(userId);
        //String username = userVerify.getUsername();
        String userInfo = request.getUsername() + userId.toString();

        List<Long> productIds = request.getProductIds();

        RMap<String, CartProductDto> map = redissonClient.getMap(userInfo);
        for (Long productId : productIds) {
            Item item = itemMapper.selectByPrimaryKey(productId);
            //CartProductDto cartProductDto = cartItemConverter.item2Dto(item);



            map.remove(item);

        }

    }
}
